package com.itheima.d2_byte_stream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：使用字节流完成对文件的复制操作。
     数据源
     目的地
 */
public class CopyTest5 {
    public static void main(String[] args) throws Exception {
        copyFile1();
        copyFile2();
    }

    //
    public static void copyFile1() throws IOException {
        String source = "D:\\test\\source\\th.jfif";
        String dest = "D:\\test\\dest\\itheima1.jfif";
        //创建输入流对象关联文件
        FileInputStream fis = new FileInputStream(source);
        //创建输出流对象关联目标文件
        FileOutputStream fos = new FileOutputStream(dest);
//利用循环

        int date = -1;
        while ((date = fis.read()) != -1) {
            fos.write(date);
        }
        fis.close();
        fos.close();
    }

    //
    public static void copyFile2() throws IOException {
        String source = "D:\\test\\source\\th.jfif";
        String dest = "D:\\test\\dest\\itheima2.jfif";
        //创建输入流对象关联文件
        FileInputStream fis = new FileInputStream(source);
        //创建输出流对象关联目标文件
        FileOutputStream fos = new FileOutputStream(dest);

        byte[] buf = new byte[1024];
        int l = -1;
        while ((l = fis.read(buf)) != -1) {
            fos.write(buf, 0, l);
        }

        fis.close();
        fos.close();

    }
}
